<template>
	<view class="select_member">
		<view class="member">
			<u-search v-model="name" @change="queryList" :show-action="false" placeholder="请输入搜索关键词" />
			<view class="list">
				<view class="li" v-for="(item,index) in list" :key="index">
					<label class="radio">
						<view class="li_name" @click="selectItem(index)">
							<radio color="#03aa96" :value="String(item.id)" :checked="item.isSelect" v-if="item.isSelect"/>
							<image :src="item.img ? item.img : BASE_IMG_URL+'headImg.png'" class="staffimg" mode=""></image>
							<view class="name">{{item.name}}</view>
							<view class="post">{{item.post}}</view>
						</view>
					</label>
				</view>
				<view style="height: 150rpx;"></view>
				<u-empty v-if="list.length == 0" text="暂无更多"></u-empty>
			</view>
			<view class="bottomli">
				<view class="remove btn" @click="quxiao">取消</view>
				<view class="sure btn" @click="queding">确定</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		netStaffList
	} from '@/api/kehu.js'
	import {
		BASE_IMG_URL
	} from '@/util/api.js'
	export default {
		data() {
			return {
				goodsId: 0,
				list: [],
				name: '',
				selectInfo: [],
				type: null, //选择上级
				BASE_IMG_URL: BASE_IMG_URL,
			}
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type
			}
			if (options.goodsId) {
				this.goodsId = options.goodsId
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList() {
				let params = {
					name: this.name
				}
				netStaffList(params).then(res => {
					res = res.data
					res.forEach(ele => {
						ele.isDel = true
						ele.isSelect = false
						ele.goodsId = this.goodsId
					})
					this.list = res
				})
			},
			selectItem(index) {
				if (this.type == 1) {
					let arr = this.list
					arr.forEach(ele => {
						ele.isSelect = false
					})
					this.list = arr
				}
				let obj = this.list[index]
				obj.isSelect = !obj.isSelect
				this.$set(this.list,index,obj)
			},
			queding() {
				if (this.type == 1) {
					let arr = this.list
					let selectInfo = null
					arr.forEach(ele => {
						if (ele.isSelect) {
							selectInfo = ele
						}
					})
					uni.setStorageSync('parentinfo', selectInfo)
				} else {
					let arr = []
					let x = uni.getStorageSync('cashierStaffs')
					if (x.length != 0) {
						arr = arr.concat(x)
					}
					this.list.forEach(ele => {
						if (ele.isSelect) {
							arr.push(ele)
						}
					})
					console.log("44444444")
					uni.setStorageSync('cashierStaffs', arr)
				}
				uni.navigateBack({
					delta: 1
				})
			},

			quxiao() {
				uni.navigateBack({
					delta: 1
				})
			},
			//搜索
			queryList(e) {
				this.name = e
				this.getList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		padding: 20rpx 24rpx 150rpx;
		background: #fff;

		.li {
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding: 20rpx 0;
			border-bottom: 1rpx solid #EAEAEA;

			.li_name {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				line-height: 55rpx;
			}
			.radio {
				width: 100%;
			}
			.staffimg{
				width:40rpx;
				height:40rpx;
				border-radius: 50%;
				margin-left: 24rpx;
			}
			.name {
				font-size: 24rpx;
				color: #333333;
				margin-left: 24rpx;
			}
			.post {
				font-size: 24rpx;
				color: #666666;
				margin-left: 24rpx;
			}
		}
	}

	.bottomli {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 750rpx;
		height: 120rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		background: #fff;
		border-top: 1rpx solid #EAEAEA;

		.btn {
			width: 300rpx;
			height: 80rpx;
			font-size: 24rpx;
			color: #666666;
			text-align: center;
			line-height: 80rpx;
			border-radius: 40rpx;
		}

		.sure {
			background: #03aa96;
			color: #fff;
		}

		.remove {
			border: 1rpx solid #03aa96;
			color: #03aa96;
			line-height: 78rpx;
		}
	}

	.radio {
		radio {
			transform: scale(0.6);
		}
	}
</style>
